// 获取24小时中每隔15分钟共96个时间段的数组
function divide24Hours() {
  var timeNodes = [];
  for (var hour = 0; hour < 24; hour++) {
    for (var minute = 0; minute < 60; minute += 15) {
      var time = ("0" + hour).slice(-2) + ":" + ("0" + minute).slice(-2);
      timeNodes.push(time);
    }
  }
  return timeNodes;
}
export const timeArray = divide24Hours();


// 获取某个月份的天数
 function  getDaysInMonth(year, month) {
  var date = new Date(year, month - 1, 1);
  var days = [];
  while (date.getMonth() === month - 1) {
    days.push(new Date(date));
    date.setDate(date.getDate() + 1);
  }
  return days;
}
export { getDaysInMonth };


// 获取月份
function getmonth() {
  const comtharrs = []
  for (let i = 1; i < 13; i++) {
    
    comtharrs.push(i+'月')
  }
  return comtharrs
}
 
export const monthArray = getmonth()

// 数组排序
function setlistsort(arr1, arr2) {
   const newarr=[]
   for (let i = 0; i < arr2.length; i++) {
    for (let j = 0; j < arr1.length; j++) {
      if (arr1[j].trialProjectName == arr2[i]) {
          newarr.push(arr1[j]);
        }
    }
}
  return newarr
}
export { setlistsort }

export const ColorList = ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc', '#f99e1c',  '#f7f1bd', '#3e0317',  '#6569b0',  '#b53b54', '#a5446f', '#f2684b', '#e73451',
  '#e65656', '#f89a1c', '#aeb92c', '#4eb849', '#f68a5c', '#baa635', '#f26355', '#e2631e', '#fde404', '#7eb138', '#9ea718', '#94a76f', '#d0b24f', '#8eb646', '#faef07', '#c1ba07', '#8f1c53',
  '#b34039', '#ba9232', '#8b6439', '#a2b029', '#718933', '#a2bb2b', '#62aa3c', '#03a653', '#038549', '#28b44b', '#a3a830', '#7ac141', '#5e9a80', '#8b8c90', '#beb276', '#fefef4',
  '#744e03','#a3a36f','#c9b583','#978847','#9d977f','#cc7b6a','#db646a','#80a89d','#def2fd','#7a9bae','#039fb8','#5e777b','#120c0c','#caa465','#dfbd7e','#b9a449' 
]

// 编写递归转换echart中树结构
function  convertChildrenListToChildren(obj, colors) {
  let colorIndex = 0;
  if (obj.childrenList) {
    obj.children = obj.childrenList.map(child => {
      const color = colors[colorIndex];
      colorIndex = (colorIndex + 1) % colors.length; // 循环使用颜色数组中的颜色
      return {
        ...convertChildrenListToChildren(child, colors),
        itemStyle: {
          color: color
        }
      };
    });
    delete obj.childrenList;
  }
  return obj;
}
export { convertChildrenListToChildren }

function shuffleArray(array) {
  let currentIndex = array.length, temporaryValue, randomIndex;

  // While there remain elements to shuffle...
  while (0 !== currentIndex) {

      // Pick a remaining element...
      randomIndex = Math.floor(Math.random() * currentIndex);
      currentIndex -= 1;

      // And swap it with the current element.
      temporaryValue = array[currentIndex];
      array[currentIndex] = array[randomIndex];
      array[randomIndex] = temporaryValue;
  }

  return array;
}
export { shuffleArray }

function  infinitScroll (dom) {
  // 拿到表格挂载后的真实DOM
    // const table = document.getElementById(dom);
    const table = dom
    // 拿到表格中承载数据的div元素
      const divData = table
    divData.onmouseover = function () {
    clearInterval(t)
    } //鼠标移入，停止滚动
    divData.onmouseout = function () {
            start()
          } //鼠标移出，继续滚动
    // 拿到元素后，对元素进行定时增加距离顶部距离，实现滚动效果(此配置为每100毫秒移动2像素)
    let t
    function start () {
    // 数据少于表格高度停止滚动
    if (divData.clientHeight > divData.scrollHeight) {
      return
      }
    t = setInterval(() => {
    // 元素自增距离顶部1像素
    divData.scrollTop += 2
      // 判断元素是否滚动到底部(可视高度+距离顶部=整个高度)
    if (divData.clientHeight + divData.scrollTop > divData.scrollHeight-1) {
    // 重置table距离顶部距离
      divData.scrollTop = 0
        }
      }, 100)
    }
    start()
}
export { infinitScroll }
export const dayarray=['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31']
export const indexarray = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95]
// 获取24小时中每隔15分钟共96个时间段的数组
// function divide24Hours() {
//   var timeNodes = [];
//   for (var hour = 0; hour < 24; hour++) {
//     for (var minute = 0; minute < 60; minute += 15) {
//       var time = ("0" + hour).slice(-2) + ":" + ("0" + minute).slice(-2);
//       timeNodes.push(time);
//     }
//   }
//   return timeNodes;
// }
// export const timearrays = divide24Hours();